<!DOCTYPE html>
<html>
<#include "/views/ftl/base/manager_include.ftl">
<script type="text/javascript" src="${basePath}js/My97DatePicker/WdatePicker.js"></script>
<base href="${basePath}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加产品</title> 
</head>
<body style="background:#eef3f7;">
<#include "/views/ftl/base/head.ftl"> 
<div class="Main">
  <div class="dw">
<#include "/views/ftl/base/menu.ftl">
<#function a><#return "产品_List"></#function> 
<!--右边内容-->
<div class="Rightbox fl">
    <!--导航-->
    <div class="Bread_crbs clear">
      <div class="Bread_crbs_img fl"></div>
      <div class="Bread_crbs_text fl">
      	<a href="javascript:void(0);"><span>商品管理</span></a>
      	<span class="fnt_famy">></span>
      	<a href="javascript:void(0);"><span>添加产品</span></a>
      </div>
    </div>
      
      <!-- 
    Long brandId =tempGoods.getBrandId();
	Long goodsCategoryId =tempGoods.getGoodsCategoryId();
	
	String goodsNumber = tempGoods.getGoodsNumber();
	String goodsName =tempGoods.getGoodsName();
	 
	//String goodsDescription = tempGoods.getGoodsDescription();
	//String goodsBarcode = tempGoods.getGoodsBarCode();
	
	//String range=tempGoods.getRangeStr();
	Double tagPrice=tempGoods.getTagPrice(); // 吊牌价
	Double retailPrice=tempGoods.getRetailPrice(); // 销售价格
	String unit=tempGoods.getUnit();
	
	String year=tempGoods.getYear(); // 年份
	String season=tempGoods.getSeason(); // 季节
	Integer applySex=tempGoods.getApplySex(); // 0 女 1 男 2 全部
	//Double wholeSalePrice=tempGoods.getWholeSalePrice();//
	String goodsRemark=tempGoods.getGoodsRemark();
      -->
  <!--表格列表-->
        <div class="fl">
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;display:none;">
             <span class="left_title"  >品牌：</span>
             <select id="brand_list_select" name="brandId"    class="sp" style="width: 220px;">
           			<option value="">----</option> 
			 </select>
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title"  >一级分类：</span>
             <select id="first_goods_category_list_select"   class="sp" style="width: 220px;">
           			<option value="">----</option> 
			 </select>
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title"  >二级分类：</span>
             <select id="second_goods_category_list_select"   class="sp" style="width: 220px;">
           			<option value="">----</option> 
			 </select>
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;display:none;">
             <span class="left_title"  >适用：</span>
             <select name="applySex"   class="sp" style="width: 220px;">
             	<option value="">----</option> 
             	<#list applySexTypeEnum as enum > 
             			<option value="${enum.type}" selected="selected">${enum.typeName}</option> 
           		 </#list> 
			 </select>
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title" style="line-height: 32px;">单位：</span>
             <select name="unit"   class="sp" style="width: 220px;>
            		<option value="">---</option>  
           			 <#list unitList as subject>   
           			 		<option value="${subject}">${subject}</option>    
            		 </#list>
			 </select> 

          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;display:none;">
             <span class="left_title" style="line-height: 32px;"  >年份：</span>
             <input type="text" name="year" class="search_text tdd50" style="width:210px" value=""> 
          </div>
          
         
          <div class="input_name" style="display:none;">
             <span class="left_title" style="line-height: 32px;">季节：</span>
             <select name="season"   class="sp" style="width: 220px;>
            		 <option value="">---</option>  
           			<#list seasonList as subject>  
            		 	<option value="${subject}">${subject}</option>   
            		 </#list>
			 </select>
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title" style="line-height: 32px;">产品编号：</span>
             <input type="text" name="goodsNumber" class="search_text tdd50" style="width:210px" value="${(newGoodsNumber)!''}"> 
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title" style="line-height: 32px;">产品名称：</span>
             <input type="text" name="goodsName" class="search_text tdd50" style="width:210px" value=""> 
          </div>
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title" style="line-height: 32px;">价格：</span>
             <input type="text" name="retailPrice" class="search_text tdd50" style="width:210px" value="">
          </div> 

          
          
          <div class="input_name" style="height:32px;margin-bottom: 20px;">
             <span class="left_title" style="line-height: 32px;">备注:</span>
             <input type="text" name="goodsRemark" class="search_text tdd50" style="width:210px" value=""> 
          </div>
          
		 
		 <span class="tbl_btn" style="margin-left: 300px;"> 
             	<a href="javascript:void(0);"><span id="save" style="background: #0075c5;">保存</span></a>
         </span>
          
        </div>
        
</div>
</div>  
<script> 
$(function(){

	
	
	loadfirstGoodsCategoryList();
	function loadfirstGoodsCategoryList(){
		$.ajax({
			url : "${basePath}manager/GoodsCategory_goodsCategoryList",
			data : { 
				pageNumber:1,
				pageSize:100
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){
					 	html+='<option value="'+bean.id+'">'+bean.categoryName+'</option> '; 
					 });
					 $('#first_goods_category_list_select').html(html);
				} 
			}
		}); 
	}
	
	 $('#first_goods_category_list_select').change(function(){
	 	var parentId=$('#first_goods_category_list_select').val();
	 	loadSecondGoodsCategoryList(parentId);
	 	
	 	var goodsCategoryId =$('#first_goods_category_list_select').find("option:selected").val();
	 	var goodsName=$('#first_goods_category_list_select').find("option:selected").text();
	 	if(goodsCategoryId==''){
	 		$('input[name=goodsName]').val('');
	 	}else{
	 		$('input[name=goodsName]').val(goodsName);
	 	}
	 	
	 	
	 });
	 
	 $('#second_goods_category_list_select').change(function(){
	 	
	 	var goodsName= $('#second_goods_category_list_select').find("option:selected").text();
	 	var goodsCategoryId =$('#second_goods_category_list_select').val();
	 	if(goodsCategoryId==''){
	 		goodsName=$('#first_goods_category_list_select').find("option:selected").text();
	 		$('input[name=goodsName]').val(goodsName);
	 	}else{
	 		$('input[name=goodsName]').val(goodsName);
	 	}
	 	
	 });
	
	function loadSecondGoodsCategoryList(parentGoodsCategoryId){
		if('' == parentGoodsCategoryId){
			var html ='';
			html+='<option value="">----</option>';
			$('#second_goods_category_list_select').html(html);
			return ;
		}
	
		$.ajax({
			url : "${basePath}manager/GoodsCategory_goodsCategoryList",
			data : { 
				goodsCategoryParentId:parentGoodsCategoryId,
				pageNumber:1,
				pageSize:100
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){
					 	html+='<option value="'+bean.id+'">'+bean.categoryName+'</option> '; 
					 });
					 $('#second_goods_category_list_select').html(html);
				} 
			}
		});
		
	
	}

	
	
	loadBrandList();
	function loadBrandList(){
		$.ajax({ 
			url : "${basePath}manager/Brand_brandList",
			data : { 
				pageNumber:1,
				pageSize:100
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){
					 	html+='<option value="'+bean.id+'">'+bean.brandName+'</option> '; 
					 });
					 $('#brand_list_select').html(html);
				} 
			}
		});
	
	}

	
	
	$("#save").click(function(){
		
		var brandId = $('#brand_list_select').val();
		var first_goods_category_id = $('#first_goods_category_list_select').val();
		var second_goods_category_id = $('#second_goods_category_list_select').val();
		
		var goodsCategoryId =first_goods_category_id;
		if(second_goods_category_id!=''){
			goodsCategoryId=second_goods_category_id;
		}
		
		var goodsNumber=$("input[name=goodsNumber]").val();
		var goodsName=$("input[name=goodsName]").val();
		var retailPrice=$("input[name=retailPrice]").val();
		var unit=$("select[name=unit]").val();//
		var year=$("input[name=year]").val();//
		var season=$("select[name=season]").val();//
		var applySex=$("select[name=applySex]").val();
		var goodsRemark=$("input[name=goodsRemark]").val();//
		
		/*if(brandId==''){
			alert("请选择品牌");
			return;
		}*/
		if(goodsCategoryId==''){
			alert("请选择分类分类");
			return;
		}
		if(goodsNumber==''){
			alert('产品号不能为空');
			return ;
		}
		if(goodsName==''){
			alert('产品名称不能为空');
			return ;
		}
		if(retailPrice==''){
			alert('价格不能为空');
			return ;
		}
		if(applySex==''){
			alert("请选择适用群体");
			return ;
		}
		
		$.ajax({ 
			url : "${basePath}manager/Goods_createGoods",
			data : { 
				brandId:brandId,
				goodsCategoryId:goodsCategoryId,
				goodsNumber:goodsNumber,
				goodsName:goodsName,
				retailPrice:retailPrice,
				unit:unit,
				year:year,
				season:season,
				applySex:applySex,
				goodsRemark:goodsRemark
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					alert(dat.msg);
					//window.location.href="${basePath}manager/Goods_goodsInfo?goodsId="+dat.data.goodsId;
                    window.location.reload();
				}else{
					alert(dat.msg);	
				} 
			}
		});
	});

});

</script>
</body>
</html>

